package hot_100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class 字母异位词分组 {
    public static void main(String[] args) {

    }

    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] ch = str.toCharArray();
            Arrays.sort(ch);
            String s = String.valueOf(ch);
            List<String> list = map.computeIfAbsent(s, f -> new ArrayList<>());
            list.add(str);
        }
        List<List<String>> ans = new ArrayList<>();
        map.forEach((k, v) -> {
            ans.add(v);
        });
        return ans;
    }
}
